package com.jinzecloud.reportapproval.controller;

import com.jinzecloud.reportapproval.constant.AdminSwaggerTagConst;
import com.jinzecloud.reportapproval.form.MenuAddForm;
import com.jinzecloud.reportapproval.form.MenuUpdateForm;
import com.jinzecloud.reportapproval.service.MenuService;
import com.jinzecloud.reportapproval.utils.R;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 菜单
 */
@RestController
@CrossOrigin
@Api(tags = "菜单管理",value = "菜单管理")
@Tag(name = AdminSwaggerTagConst.System.SYSTEM_MENU)
public class MenuController {

    @Resource
    private MenuService menuService;

    @Operation(summary = "添加菜单")
    @PostMapping("/menu/add")
//    @SaCheckPermission("system:menu:add")
    public R addMenu(@RequestBody @Valid MenuAddForm menuAddForm) {
        menuAddForm.setCreateUserId(1L);//获取用户ID

        return R.ok().put("data",menuService.addMenu(menuAddForm));
    }

    @Operation(summary = "更新菜单")
    @PostMapping("/menu/update")
//    @SaCheckPermission("system:menu:update")
    public R updateMenu(@RequestBody MenuUpdateForm menuUpdateForm) {

        menuUpdateForm.setUpdateUserId(1L);//获取用户ID
        return menuService.updateMenu(menuUpdateForm);
    }

    @Operation(summary = "批量删除菜单")
    @GetMapping("/menu/batchDelete")
//    @SaCheckPermission("system:menu:batchDelete")
    public R batchDeleteMenu(@RequestParam("menuIdList") List<Long> menuIdList) {
        return menuService.batchDeleteMenu(menuIdList,1L);//获取用户ID
    }

    @Operation(summary = "查询菜单列表")
    @GetMapping("/menu/query")
    public R queryMenuList() {
        return R.ok().put("data",menuService.queryMenuList(null));
    }

    @Operation(summary = "查询菜单详情")
    @GetMapping("/menu/detail/{menuId}")
    public R getMenuDetail(@PathVariable Long menuId) {
        return menuService.getMenuDetail(menuId);
    }

    @Operation(summary = "查询菜单树 ")
    @GetMapping("/menu/tree")
    public R queryMenuTree(@RequestParam("onlyMenu") Boolean onlyMenu) {
        return menuService.queryMenuTree(onlyMenu);
    }

    @Operation(summary = "获取所有请求路径")
    @GetMapping("/menu/auth/url")
    public R getAuthUrl() {
        return menuService.getAuthUrl();
    }
}
